package com.example.bnuzzu.mapper;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.bnuzzu.common.dto.HouseListDto;
import com.example.bnuzzu.common.dto.UserListDto;
import com.example.bnuzzu.entity.Userinfo;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author BNUZZU
 * @since 2021-04-13
 */
@Repository
public interface UserinfoMapper extends BaseMapper<Userinfo> {
    /**
     * 房屋搜索页面分页查询 返回列表 一页6个数据
     * @param page 分页对象
     * @param state 状态
     * @return
     */
    @Select("SELECT user.UserID,user.UserName,user.Sex,user.Age,user.Phone,user.Email,user.UserType" +
            " FROM userinfo user"+
            " WHERE user.State=${state} ")
    IPage<UserListDto> selectPageVo(Page<?> page, Integer state);

    @Select("SELECT DISTINCT users.* FROM userinfo users,orderinfo orders where (orders.OwnerID =users.UserID or orders.TenantID = users.UserID) " +
            "AND orders.HouseID = #{houseid}")
    List<UserListDto> findFriends(Integer houseid);

    @Select("SELECT * FROM userinfo")
    List<Userinfo> getAllUser();

}
